//
//  MyRepairViewController.swift
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/31.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import UIKit

class MyRepairViewController: BasePresentedViewController {

    lazy var infoListView: InfoListView = {
        let infoListView = InfoListView()
        infoListView.datasource = self
        infoListView.tableView.registerCellNib(with: MyMTOImageCell.self)
        return infoListView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        containerView.addSubview(infoListView)
        let inset = UIEdgeInsetsMake(0, 30, 0, 30)
        infoListView.mas_makeConstraints { (make) in
            make?.width.equalTo()(containerView)
            make?.edges.equalTo()(containerView)?.insets()(inset)
        }
        let config = JSFromCellItemConfig(text: "订单号:", font: UIFont.systemFont(ofSize: 12), textColor: .themeDarkGrayColor, scale: 0.3, alignment: .right, insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
        let config2 = JSFromCellItemConfig(text: "212112312312312312312312312312321321312321", font: UIFont.systemFont(ofSize: 12), textColor: .themeDarkGrayColor, scale: 0.6, insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
        configs = [config, config2]
        view.layoutIfNeeded()
    }

    var configs: [JSFromCellItemConfig] = []

    let titles = ["订单详情", "客户信息", "详细信息"]
}


extension MyRepairViewController: InfoListViewDatasource {


    func listView(_ listVeiw: InfoListView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: InfoListFormCell = listVeiw.tableView.dequeueReusableCell(for: indexPath)
        cell.backgroundColor = UIColor.themebackgroundColor
        cell.formView.delegate = self
        cell.formView.tag = indexPath.section
        return cell
    }

    func listView(_ listView: InfoListView, headerTextsInSection section: Int) -> [String] {
        return [titles[section]]
    }

    func listView(_ listView: InfoListView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }

    func numberOfSections(in listView: InfoListView) -> Int {
        return titles.count
    }
}

extension MyRepairViewController: JSFormViewDelegate {
    func formView(_ formView: JSFormView, insetsForCellAt index: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    }

    func numberOfColumns(in formView: JSFormView) -> Int {
        switch formView.tag {
        case 2: return 1
        default: return 3
        }
    }

    func numberOfCells(in formView: JSFormView) -> Int {
        return 10
    }

    func formView(_ formView: JSFormView, configForColumnAt index: Int) -> [JSFromCellItemConfig] {
        switch formView.tag {
        case 2:
            let config = JSFromCellItemConfig(text: "尺寸信息", font: UIFont.systemFont(ofSize: 12), scale: 0.1, alignment: .right, insets: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20))
            let config2 = JSFromCellItemConfig(text: "单排一粒扣", font: UIFont.systemFont(ofSize: 14), scale: 0.9, alignment: .left, insets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 20))
            return [config, config2]
        default: return configs
        }
    }
}
